package com.lhkj.ct.base.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.lhkj.ct.base.constants.SystemConstants;
import com.lhkj.ct.base.enums.DataScope;
import com.lhkj.ct.base.enums.LoginWay;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Set;

/**
 * <p>
 * 用户缓存
 * </p>
 */
public class LoginUser implements Serializable {

    /**
     * shiro session缓存管理key
     */
    private String sessionKey;

    /**
     * 用户id
     */
    private String userId;

    /**
     * 用户类型 1.后台人员 2.平台用户
     */
    private Integer userType;

    /**
     * 登录名/账号
     */
    private String loginName;

    /**
     * 姓名
     */
    private String userName;

    /**
     * 科室id
     */
    private String deptId;

    /**
     * 机构id
     */
    private String organId;

    /**
     * 数据权限
     */
    private DataScope dataScope;

    /**
     * 登录方式
     */
    private LoginWay loginWay;

    /**
     * 登录时间
     */
    private Long loginTime;

    /**
     * 登录IP地址
     */
    private String ipaddr;

    /**
     * 登录地点
     */
    private String loginLocation;

    /**
     * 浏览器类型
     */
    private String browser;

    /**
     * 操作系统
     */
    private String os;

    /**
     * 用户shiro校验角色,非系统内角色管理的角色
     * <p>
     * root: 超级管理员
     * admin：后台
     * user：前台
     */
    private Set<String> shiroRoles;

    /**
     * 第三方登录标识
     */
    private String identifier;

    /**
     * 是否超级管理员
     */
    @JsonIgnore
    public boolean isRoot() {
        return StringUtils.equals(SystemConstants.ROOT_LOGIN_NAME, loginName);
    }

    public String getSessionKey() {
        return sessionKey;
    }

    public void setSessionKey(String sessionKey) {
        this.sessionKey = sessionKey;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public Integer getUserType() {
        return userType;
    }

    public void setUserType(Integer userType) {
        this.userType = userType;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getDeptId() {
        return deptId;
    }

    public void setDeptId(String deptId) {
        this.deptId = deptId;
    }

    public String getOrganId() {
        return organId;
    }

    public void setOrganId(String organId) {
        this.organId = organId;
    }

    public DataScope getDataScope() {
        return dataScope;
    }

    public void setDataScope(DataScope dataScope) {
        this.dataScope = dataScope;
    }

    public LoginWay getLoginWay() {
        return loginWay;
    }

    public void setLoginWay(LoginWay loginWay) {
        this.loginWay = loginWay;
    }

    public Long getLoginTime() {
        return loginTime;
    }

    public void setLoginTime(Long loginTime) {
        this.loginTime = loginTime;
    }

    public String getIpaddr() {
        return ipaddr;
    }

    public void setIpaddr(String ipaddr) {
        this.ipaddr = ipaddr;
    }

    public String getLoginLocation() {
        return loginLocation;
    }

    public void setLoginLocation(String loginLocation) {
        this.loginLocation = loginLocation;
    }

    public String getBrowser() {
        return browser;
    }

    public void setBrowser(String browser) {
        this.browser = browser;
    }

    public String getOs() {
        return os;
    }

    public void setOs(String os) {
        this.os = os;
    }

    public Set<String> getShiroRoles() {
        return shiroRoles;
    }

    public void setShiroRoles(Set<String> shiroRoles) {
        this.shiroRoles = shiroRoles;
    }

    public String getIdentifier() {
        return identifier;
    }

    public void setIdentifier(String identifier) {
        this.identifier = identifier;
    }

    public static LoginUserBuilder builder() {
        return new LoginUserBuilder();
    }

    public static class LoginUserBuilder {
        private final LoginUser loginUser;

        public LoginUserBuilder() {
            loginUser = new LoginUser();
        }

        public LoginUserBuilder sessionKey(String sessionKey) {
            this.loginUser.sessionKey = sessionKey;
            return this;
        }

        public LoginUserBuilder userType(Integer userType) {
            this.loginUser.userType = userType;
            return this;
        }

        public LoginUserBuilder userId(String userId) {
            this.loginUser.userId = userId;
            return this;
        }

        public LoginUserBuilder loginName(String loginName) {
            this.loginUser.loginName = loginName;
            return this;
        }

        public LoginUserBuilder userName(String userName) {
            this.loginUser.userName = userName;
            return this;
        }

        public LoginUserBuilder deptId(String deptId) {
            this.loginUser.deptId = deptId;
            return this;
        }

        public LoginUserBuilder organId(String organId) {
            this.loginUser.organId = organId;
            return this;
        }


        public LoginUserBuilder shiroRoles(Set<String> shiroRoles) {
            this.loginUser.shiroRoles = shiroRoles;
            return this;
        }

        public LoginUserBuilder ipaddr(String ipaddr) {
            this.loginUser.ipaddr = ipaddr;
            return this;
        }

        public LoginUserBuilder loginLocation(String loginLocation) {
            this.loginUser.loginLocation = loginLocation;
            return this;
        }

        public LoginUserBuilder loginTime(Long loginTime) {
            this.loginUser.loginTime = loginTime;
            return this;
        }

        public LoginUserBuilder browser(String browser) {
            this.loginUser.browser = browser;
            return this;
        }

        public LoginUserBuilder os(String os) {
            this.loginUser.os = os;
            return this;
        }

        public LoginUserBuilder identifier(String identifier) {
            this.loginUser.identifier = identifier;
            return this;
        }

//        public LoginUserBuilder roles(Set<String> roles) {
//            this.loginUser.roles = roles;
//            return this;
//        }

        public LoginUser build() {
            return this.loginUser;
        }
    }
}
